#include <stdio.h>
#include <iostream>
#include "K8055D_C.h"
#include "resource.h"
#include "conio.h"
#include <cstdlib>

using namespace std;

void CheckInputs(bool screen = true);

bool inputflag = false;

int main()
{
	// open communication with K8055D
	OpenDevice(0);

	// check for sticky inputs
	CheckInputs();

	cout << "Inital Check Complete" << endl;
	_getch();
	system("CLS");	
	
	do
	{
		CheckInputs(false);

		if (ReadDigitalChannel(5))
		{
			ClearAllDigital();
			inputflag = false;
		}
	}
	while (1); // loop while button 5 is not depressed
	
	ClearAllDigital();
	cout << "Press any key to continue...";
	_getch();
	
	CloseDevice();
	return 0;
}

void CheckInputs(bool screen)
{
	for (int i = 1; i <= 5; i++)
	{
		bool inputstatus = false;

		inputstatus = ReadDigitalChannel(i);

		if (inputstatus)
		{
			if (screen)
			{
				cout << "Input " << i << " depressed" << endl;	
				inputflag = true;
			}
			else
			{
				if (i != 5)
					if (!inputflag)
					{
						SetDigitalChannel(i);
						inputflag = true;
					}
					else;
				else;
			}
			
		}
		else;
	}

	if (inputflag == false && screen == true)
	{
		cout << "No inputs depressed\n" << endl;
		ClearAllDigital();
	}
	else;

	return;
}